﻿#include "mainwindow.h"

#include <QDebug>
#include <QFileDialog>

MainWindow::MainWindow(QWidget *parent)
    : QMainWindow(parent)
    , m_parseObjBtn(new QPushButton(tr("解析"),this))
    , m_modelWidget(new ModelWidget(this))
    , m_mainCentralWidget(new QWidget(this))
{
    this->initConnect();

    this->initLayout();



    this->resize(800,600);
}

MainWindow::~MainWindow()
{
}


void MainWindow::initConnect()
{
    connect(m_parseObjBtn,&QPushButton::clicked,m_modelWidget,[&](){

        QString objFilePath = QFileDialog::getOpenFileName(this,tr("请选择模型OBJ文件"),"E:/data/Gen3D/data",tr("模型文件(*.obj *.OBJ);;所有文件(*.*)"));
        qDebug()<<"选择的OBJ文件"<<objFilePath;

        QString mtlFilePath = QFileDialog::getOpenFileName(this,tr("请选择模型材料MTL文件"),"E:/data/Gen3D/data",tr("材料文件(*.mtl *.MTL);;所有文件(*.*)"));
        qDebug()<<"选择的MTL文件"<<mtlFilePath;

        m_modelWidget->parseModelFile(objFilePath,mtlFilePath);
        //m_modelWidget->parseModelFile("E:/data/Gen3D/Gen3D_Qt/data/data.obj","E:/data/Gen3D/data/material.mtl");
    });
}

void MainWindow::initLayout()
{
    m_mainVBoxLayout = new QVBoxLayout(m_mainCentralWidget);
    {
        // 模型展示窗口
        m_mainVBoxLayout->addWidget(m_modelWidget);

        // 确认解析模型文件按钮
        m_mainVBoxLayout->addWidget(m_parseObjBtn);
    }

    m_mainCentralWidget->setLayout(m_mainVBoxLayout);
    this->setCentralWidget(m_mainCentralWidget);
}

